from selenium.webdriver.common.by import By
from Base.base_page import BasePage
from Utils.readConfig import Read_Config

class LoginPage(BasePage):
    readUrl = Read_Config()
    URL = readUrl.get_info("testServer","url")+"/Home/user/login.html"

    # 页面关联的元素对象
    userName_Ele = (By.XPATH, "//*[@id='username']")  #用户名
    password_Ele = (By.ID, "password")                #密码
    verify_code_Ele = (By.NAME, "verify_code")        #验证码
    button_Ele = (By.CLASS_NAME, "J-login-submit")    #登录按钮
    close_alter_Ele = (By.CLASS_NAME, "layui-layer-btn0") #关闭按钮

    # 登录流程
    def login(self, account, password, verify_code):
        print(self.URL)
        self.visit(self.URL)
        self.input(self.userName_Ele, account)
        self.input(self.password_Ele, password)
        self.input(self.verify_code_Ele, verify_code)
        self.click(self.button_Ele)
        if self.find_element(self.close_alter_Ele):
            self.click(self.close_alter_Ele)
